<!DOCTYPE html>
<html>
<head>
    <link rel="shortcut icon" href="/b_videos/favicon.ico">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>b站视频下载 - 哔哩哔哩视频下载器 - 在线下载B站视频/音频 | 免费无水印</title>
    <meta name="description" content="免费在线下载哔哩哔哩(B站)高清视频/音频，支持输入BV号或链接，无需安装软件，一键解析下载MP4视频或MP3音频，简单快捷无广告">
    <meta name="keywords" content="哔哩哔哩下载,b站视频下载,bilibili下载,在线下载B站视频,下载BV号视频,B站MP4下载,B站音频提取,免费B站下载工具">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta http-equiv="Cache-Control" content="no-siteapp">

    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
        }
        h1 {
            color: #fb7299; /* B站粉色 */
            text-align: center;
        }
        .container {
            background-color: #f5f5f5;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 15px;
        }

        input[type="text"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        button[disabled] {
            opacity: 0.7;
            cursor: not-allowed;
        }
        button:hover:not([disabled]) {
            background-color: #e45f85;
        }
        #result {
            margin-top: 20px;
            padding: 10px;
            border-radius: 4px;
        }

        #downloadForm {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        .form-actions {
            display: flex;
            justify-content: flex-end;
        }

        .status-message {
            margin-top: 20px;
            padding: 10px;
            border-radius: 4px;
            text-align: center;
        }
        .success {
            background-color: #dff0d8;
            color: #3c763d;
        }
        .error {
            background-color: #f2dede;
            color: #a94442;
        }
        .processing {
            background-color: #d9edf7;
            color: #31708f;
        }
        .hidden {
            display: none;
        }
        .loading {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(255,255,255,.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease-in-out infinite;
        }
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        .button-text {
            margin-right: 8px;
        }

    </style>
</head>
<body>

<div class="container">
    <h1>B站视频下载</h1>
    <form id="downloadForm" method="post" action="/download" style="display: flex; gap: 10px;">
        <div class="form-group" style="flex-grow: 1;">
            <input type="text" id="videoUrl" name="video_url"
                   placeholder="输入B站视频链接..." required>
        </div>
        <button type="submit" style="background-color: #fb7299;" id="submitBtn">
            <span class="button-text">确定</span>
            <span class="loading hidden"></span>
        </button>
    </form>

    {% if status == "processing" %}
    <div class="status-message processing">
        正在处理，请稍候...
    </div>
    {% endif %}

    {% if status == "success" and message %}
    <div class="status-message success">
        {{ message }}
    </div>
    <div style="margin-top: 20px; text-align: center;">
        <img src="/b_videos/cover_{{ file_uuid }}.png" style="max-width: 100%; height: auto; object-fit: cover; display: block; margin: 0 auto;">
        <div style="margin-top: 20px; display: inline-block;">
            <a href="/b_videos/audio_{{ file_uuid }}.mp3" download="b_audio_{{ file_uuid }}.mp3" style="text-decoration: none;">
                <button style="margin-right: 15px; background-color: #4CAF50;">
                    下载音频
                </button>
            </a>

            <a href="/b_videos/full_video_{{ file_uuid }}.mp4" download="b_video_{{ file_uuid }}.mp4" style="text-decoration: none;">
                <button style="margin-left: 15px; background-color: #f44336;">
                    下载视频
                </button>
            </a>
        </div>
    </div>
    {% endif %}

    {% if status == "error" and message %}
    <div class="status-message error">
        {{ message }}
    </div>
    {% endif %}
</div>

<script>
    // 处理表单提交，显示加载状态
    document.getElementById('downloadForm').addEventListener('submit', function() {
        const submitBtn = document.getElementById('submitBtn');
        submitBtn.disabled = true;
        submitBtn.querySelector('.button-text').textContent = '处理中';
        submitBtn.querySelector('.loading').classList.remove('hidden');
    });
</script>

</body>
</html>
